import time
from socket import *
from threading import Thread

class Handle():
    def __init__(self,sock:socket):
        self.sock = sock

    def main(self):
        pass

class Find(Handle):
    def main(self):
        self.sock.send("Find None".encode())
        get = self.sock.recv(1024*1024)
        list_name = get.decode().split(" ")
        for item in list_name:
            print(item)

class Up_Transport(Handle):
    def main(self):
        path = input("请输入您要上传的路径")
        name = path.split("/")[-1]
        msg = "Up_Transport {}".format(name)
        self.sock.send(msg.encode())
        get = self.sock.recv(1024).decode()
        fp = open(path, "rb")
        if get == "请开始上传":
            while True:
                content = fp.read(1024)
                if not content:
                    break
                self.sock.send(content)
            time.sleep(1)
            self.sock.send("##00##".encode())
        fp.close()


class Dow_Transport(Handle):
    pass

class Quit(Handle):
    pass

class Dow_Client():
    def __init__(self,addr,poin):
        self.ADDR = (addr,poin)
        self.sock = self.creat_sock()
        self.vive = Vive()
    def main(self):
        while True:
            res = self.vive.main()
            handel = res(self.sock)
            handel.main()


    def creat_sock(self):
        sock = socket()
        sock.connect(self.ADDR)
        return sock

class Vive():

    def display(self):
        print("""================== SELECT TAB =======================
         按1键     按2键     按3键     按4键
        查询全部    上传      下载      退出
====================          =======================
        """)
    def display_select(self):
        put = input()
        if put == "1":
            return Find
        elif put == "2":
            return Up_Transport
        elif put == "3":
            return Dow_Transport
        elif put == "4":
            return Quit
    def main(self):
        self.display()
        return self.display_select()

if __name__ == '__main__':
    client = Dow_Client("127.0.0.1",8889)
    client.main()